package com.androidx.p013lv.base.utils;

import android.text.TextUtils;
import com.androidx.p013lv.base.bean.TimeBean;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Formatter;
import java.util.Locale;
import java.util.TimeZone;

/* renamed from: com.androidx.lv.base.utils.TimeUtils */
public class TimeUtils {
    public static String utc2Common(String str) {
        if (TextUtils.isEmpty(str)) {
            return "剛剛";
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.CHINA);
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("MM-dd", Locale.CHINA);
        SimpleDateFormat simpleDateFormat3 = new SimpleDateFormat("HH:mm", Locale.CHINA);
        Date date = null;
        long j = 0;
        try {
            date = simpleDateFormat.parse(str);
            SimpleDateFormat simpleDateFormat4 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
            j = simpleDateFormat4.parse(simpleDateFormat4.format(Long.valueOf(System.currentTimeMillis()))).getTime() - date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (j < 180000) {
            return "剛剛";
        }
        if (j < 3600000) {
            return (j / 60000) + "分鐘前";
        } else if (j < 86400000) {
            return (j / 3600000) + "小時前";
        } else if (j >= 172800000) {
            return simpleDateFormat2.format(date);
        } else {
            return "昨天" + simpleDateFormat3.format(date);
        }
    }

    public static TimeBean utc2appointment(String str) {
        TimeBean timeBean = new TimeBean();
        if (TextUtils.isEmpty(str)) {
            timeBean.setTimeText("剛剛");
            return timeBean;
        }
        Date date = null;
        long j = 0;
        try {
            date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.CHINA).parse(str);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
            j = simpleDateFormat.parse(simpleDateFormat.format(Long.valueOf(System.currentTimeMillis()))).getTime() - date.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (j < 180000) {
            timeBean.setTimeText("剛剛");
            return timeBean;
        } else if (j < 3600000) {
            timeBean.setTimeText((j / 60000) + "分鐘前");
            return timeBean;
        } else if (j < 86400000) {
            timeBean.setTimeText((j / 3600000) + "小時前");
            return timeBean;
        } else {
            Calendar instance = Calendar.getInstance();
            instance.setTime(date);
            int i = instance.get(5);
            timeBean.setMonth(instance.get(2) + 1);
            timeBean.setDays(i);
            return timeBean;
        }
    }

    public static String utcToLocal(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            Date parse = simpleDateFormat.parse(str);
            SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            simpleDateFormat2.setTimeZone(TimeZone.getDefault());
            if (parse != null) {
                return simpleDateFormat2.format(Long.valueOf(parse.getTime()));
            }
            return null;
        } catch (ParseException e) {
            e.printStackTrace();
            return str;
        }
    }

    public static String getFirstDayOfMonth1(int i, int i2) {
        Calendar instance = Calendar.getInstance();
        instance.set(1, i);
        instance.set(2, i2 - 1);
        instance.set(5, instance.getMinimum(5));
        return new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(instance.getTime());
    }

    public static String getLastDayOfMonth1(int i, int i2) {
        Calendar instance = Calendar.getInstance();
        instance.set(1, i);
        instance.set(2, i2 - 1);
        instance.set(5, instance.getActualMaximum(5));
        return new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(instance.getTime());
    }

    public static String stringForTime(long j) {
        long j2 = j / 1000;
        long j3 = j2 % 60;
        long j4 = (j2 / 60) % 60;
        long j5 = j2 / 3600;
        if (j5 > 0) {
            return new Formatter().format("%02d:%02d:%02d", Long.valueOf(j5), Long.valueOf(j4), Long.valueOf(j3)).toString();
        }
        return new Formatter().format("%02d:%02d", Long.valueOf(j4), Long.valueOf(j3)).toString();
    }

    public static long utc2Local(String str) {
        try {
            Date parse = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ", Locale.CHINA).parse(str);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.CHINA);
            return simpleDateFormat.parse(simpleDateFormat.format(Long.valueOf(System.currentTimeMillis()))).getTime() - parse.getTime();
        } catch (Exception e) {
            e.printStackTrace();
            return 1;
        }
    }

    public static long remainingTime(String str, String str2) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.CHINA);
            long time = simpleDateFormat.parse(str2).getTime() - simpleDateFormat.parse(str).getTime();
            if (time <= 0) {
                return 0;
            }
            return time;
        } catch (Exception unused) {
            return 0;
        }
    }

    public static long remainingTime(String str) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.CHINA);
            SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
            long time = simpleDateFormat.parse(str).getTime() - simpleDateFormat2.parse(simpleDateFormat2.format(Long.valueOf(System.currentTimeMillis()))).getTime();
            if (time <= 0) {
                return 0;
            }
            return time;
        } catch (Exception unused) {
            return 0;
        }
    }

    public static int[] getDate() {
        Calendar instance = Calendar.getInstance();
        instance.get(1);
        return new int[]{instance.get(2) + 1, instance.get(5)};
    }

    public static String utcToChina(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.CHINA);
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
        if (TextUtils.isEmpty(str)) {
            return simpleDateFormat.format(new Date());
        }
        try {
            Date parse = simpleDateFormat.parse(str);
            if (parse != null) {
                return simpleDateFormat2.format(parse);
            }
            return simpleDateFormat2.format(new Date());
        } catch (ParseException e) {
            e.printStackTrace();
            return simpleDateFormat2.format(new Date());
        }
    }

    public static String utcToChinaTwo(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ", Locale.CHINA);
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        if (TextUtils.isEmpty(str)) {
            return simpleDateFormat.format(new Date());
        }
        try {
            Date parse = simpleDateFormat.parse(str);
            if (parse != null) {
                return simpleDateFormat2.format(parse);
            }
            return simpleDateFormat2.format(new Date());
        } catch (ParseException e) {
            e.printStackTrace();
            return simpleDateFormat2.format(new Date());
        }
    }

    public static String utcToChina1(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ", Locale.CHINA);
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("M月d日", Locale.CHINA);
        if (TextUtils.isEmpty(str)) {
            return simpleDateFormat.format(new Date());
        }
        try {
            Date parse = simpleDateFormat.parse(str);
            if (parse != null) {
                return simpleDateFormat2.format(parse);
            }
            return simpleDateFormat2.format(new Date());
        } catch (ParseException e) {
            e.printStackTrace();
            return simpleDateFormat2.format(new Date());
        }
    }

    public static String utcToChina2(String str) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSSZ", Locale.CHINA);
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("MM-dd", Locale.CHINA);
        if (TextUtils.isEmpty(str)) {
            return simpleDateFormat.format(new Date());
        }
        try {
            Date parse = simpleDateFormat.parse(str);
            if (parse != null) {
                return simpleDateFormat2.format(parse);
            }
            return simpleDateFormat2.format(new Date());
        } catch (ParseException e) {
            e.printStackTrace();
            return simpleDateFormat2.format(new Date());
        }
    }

    public static String getCapitalMonth() {
        return new String[]{"一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"}[Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")).get(2)];
    }
}
